package com.gccloud.design.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gccloud.design.dao.SdRepoLimitDao;
import com.gccloud.design.entity.SdRepoLimitTimeEntity;
import com.gccloud.design.service.SdRepoTimeLimitService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.stereotype.Service;

/**
 * @author wu.yumin
 * @version 1.0.0
 * @Description 环节时限
 * @date 2021/6/29 14:29
 */
@Service
public class SdRepoTimeLimitServiceImpl extends ServiceImpl<SdRepoLimitDao, SdRepoLimitTimeEntity> implements SdRepoTimeLimitService {


    @Override
    public boolean saveLimitTime(SdRepoLimitTimeEntity entity) {
        return this.saveOrUpdate(entity);
    }

    @Override
    public boolean updateLimitTime(SdRepoLimitTimeEntity entity) {
        if(entity.getParticipantConfId() == null || entity.getParticipantConfId() == 0 ){
            throw new IllegalArgumentException("记录不存在");
        }
        UpdateWrapper<SdRepoLimitTimeEntity> updateWrapper = new UpdateWrapper();
        updateWrapper.set("FINISH_TIME_LIMIT",entity.getFinishTimeLimit()).eq("PARTICIPANT_CONF_ID",entity.getParticipantConfId());
        try {
            return update(updateWrapper);
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            return false;
        }
    }

    @Override
    public SdRepoLimitTimeEntity getById(String id) {
        return this.getOne(new QueryWrapper<SdRepoLimitTimeEntity>().eq("ACTIVITY_REPO_ID",id));
    }
}
